import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.codeInsight.folding.impl.actions.CollapseAllRegionsAction;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.FoldingModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;

public class HelloWorldAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {

        Project project = e.getData(PlatformDataKeys.PROJECT);
        final Editor editor = e.getData(CommonDataKeys.EDITOR);

        final FoldingModel fm = editor.getFoldingModel();
        final Runnable runnable = new Runnable()
        {
            @Override
            public void run() {
                final Document document = editor.getDocument();
                final String text = document.getText();

                FoldRegion foldRegion = editor.getFoldingModel().getFoldRegion(1, 100);
                if ( foldRegion == null) foldRegion = editor.getFoldingModel().addFoldRegion(1, 100, "_");
            }
        };

        fm.runBatchFoldingOperationDoNotCollapseCaret(runnable);
        String title = "标题";
        String msg = "2018,起航";
        new CollapseAllRegionsAction();
      //  CodeFoldingManager cfm=e
        Messages.showMessageDialog(project, msg, title, Messages.getInformationIcon());
    }
}